<div class="style-block" style="background: {{settings.bg_color6}}; display: none;" id="recently_view">
  <h2>Вы смотрели</h2>
  <ul class="small-prod-list" id="mod-recently-view">	
  </ul>
</div>

{% assign mod_recently_view_count = 3 %}

<script type="text/javascript">
  function saveProduct(pid) {
        if ($.cookie('product_ids') != null) {
          var arr = $.cookie('product_ids').split(',');
          for (var i = 0; i < arr.length; i++) {
            if (arr[i] == pid) {
              return;
            }
          }
          if (arr.length >= {{ mod_recently_view_count }}) {
            arr.shift();
          }
          arr.push(pid);
          $.cookie('product_ids', arr, {
            path: '/'
          });
        } else {
          $.cookie('product_ids', pid, {
            path: '/'
          });
        }
      }
  
  $(function() {   
    if($.cookie('product_ids') != null) {
      $.getJSON("/products_by_id/"+$.cookie('product_ids')+".json",
        function(data){
          var products = '';
          $.each(data.products, function(i,product){
            products += '<li><a href="/product/?product_id=' + product.id + '" class="title">'+ product.title +'</a>';
            if (product.images.length > 0) { 
            products +=  '<a href="/product/?product_id=' + product.id + '" class="img fl"><img src="'+ product.images[0].url +'" alt="'+ product.title +'" /></a>';
            products +=  '<div class="buyzone"><p class="price">'+ InSales.formatMoney(product.variants[0].base_price, "{{money_with_currency_format}}") + '</p>';
            if (product.variants[0].old_price != null) { 
              products += '<p class="old-price">' + InSales.formatMoney(product.variants[0].old_price, "{{money_with_currency_format}}")+'</p>';
            }
            products += '</div></li>';
            }
          });  
          $('#mod-recently-view').html(products);
        });
      $('#recently_view').show();
    }
    {% if template == 'product' %}
      saveProduct({{product.id}});
     {% endif %}
     });    
</script>    


